package timbap.visualizer.coreplugins;

import timbap.visualizer.api.model.PlaylistEntry;
import timbap.visualizer.api.plugin.poscloud.AbstractPosCloudPlugin;

import java.util.Comparator;

public class ReleaseYearPosCloudPlugin extends AbstractPosCloudPlugin<Integer> {
    
    private static Comparator<PlaylistEntry> playlistEntryComparator;

    @Override
    public void drawPosCloudElement(Integer pPosCloudElement, boolean pIsSelected) {
    	if (pIsSelected) {
    		getContext().getP5Applet().fill(255,200,200);
    	} else {
    		getContext().getP5Applet().fill(155,100,100);
    	}
    	getContext().getP5Applet().text(pPosCloudElement.toString(), 0, 0, 100, 100, 5);
    }

    @Override
    public Integer createPosCloudElement(PlaylistEntry pPlaylistEntry) {
    	int tYearReleased = pPlaylistEntry.getYearReleased();
    	if (tYearReleased > 0) {
    		return tYearReleased;
    	} else {
    		return 0;
    	}
    }

    public Comparator<PlaylistEntry> getPlaylistEntryComparator() {
        if (playlistEntryComparator == null) {
            playlistEntryComparator = new Comparator<PlaylistEntry>() {

                public int compare(PlaylistEntry pO1, PlaylistEntry pO2) {
                	Integer tYearReleasedO1 = pO1.getYearReleased();
                	Integer tYearReleasedO2 = pO2.getYearReleased();
                	return tYearReleasedO1.compareTo(tYearReleasedO2);
                }
                
            };
        }
        return playlistEntryComparator;
    }
    
    
}
